<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PlanetWPF.Toolbelt.Controls"
    >

  <!--Template for ImageCell types-->
  <ControlTemplate x:Key="ImageCell_Template" TargetType="{x:Type local:PowerGridCell}">
    <Border Background="{TemplateBinding Background}" 
            BorderBrush="Black"
            BorderThickness="1">
      <Image Source="{TemplateBinding CellValue}"/>
    </Border>
  </ControlTemplate>

  <!--Template for RowHeader Type-->
  <ControlTemplate x:Key="RowHeader_Template"  TargetType="{x:Type local:PowerGridCell}">
    <Border Name="RowHeader" Background="Gray"
      BorderBrush="Beige"
      BorderThickness="2">
    </Border>
  </ControlTemplate>

  <!--Template for ColumnHeader Type-->
  <ControlTemplate x:Key="ColumnHeader_Template" TargetType="{x:Type local:PowerGridHeaderCell}">
    <Border BorderBrush="Black" BorderThickness="1">
      <Label Name="PART_HeaderDisplay" AllowDrop="True" Content="{TemplateBinding CellValue}" />
    </Border>
  </ControlTemplate>


  <Style TargetType="{x:Type local:PowerGridCell}">
    <Style.Triggers>
      <Trigger Property="Selected" Value="True">
        <Setter Property="Background" Value="Blue" />
        <Setter Property="Foreground" Value="Pink"/>
      </Trigger>
      <Trigger Property="CellType" Value="Image">
        <Setter Property="Template" Value="{StaticResource ImageCell_Template}"/>
      </Trigger>
      <Trigger Property="CellType" Value="RowHeader">
        <Setter Property="Template" Value="{StaticResource RowHeader_Template}"/>
      </Trigger>
      <Trigger Property="CellType" Value="ColumnHeader">
        <Setter Property="Template" Value="{StaticResource ColumnHeader_Template}"/>
      </Trigger>
    </Style.Triggers>
    <Setter Property="CellType" Value="{Binding RelativeSource={RelativeSource Self}, Path=(CellColumn).ColumnType}"/>
    <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=(CellColumn).Width}"/>
    <Setter Property="CellPath" Value="{Binding RelativeSource={RelativeSource Self}, Path=(CellColumn).ColumnPath}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:PowerGridCell}">
          <Border Background="{TemplateBinding Background}" 
                  BorderBrush="Black"
                  BorderThickness="1"
                  Width="{TemplateBinding Width}"
                  >
            <TextBlock
                     Background="{TemplateBinding Background}"
                     Foreground="{TemplateBinding Foreground}"
                     FontFamily="{TemplateBinding FontFamily}"
                     Text="{TemplateBinding CellValue}">
            </TextBlock>

          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style BasedOn="{StaticResource {x:Type local:PowerGridCell}}" TargetType="{x:Type local:PowerGridHeaderCell}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:PowerGridHeaderCell}">
          <Border BorderBrush="Black" BorderThickness="1">
            <Label Name="PART_HeaderDisplay" AllowDrop="True" Content="{TemplateBinding CellValue}" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>